-
Notifications
You must be signed in to change notification settings - Fork 33
Expose the information in the ImageData type. #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Getting width and height of an ImageData are not effecting. - The pixel information is availalbe as a Uint8ClampedArray.
|
||
-- | An array of pixel data. | ||
foreign import data CanvasPixelArray :: * | ||
type ImageData = { width :: Number, height :: Number, data :: Uint8ClampedArray } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should Number
be Int
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much nicer than a foreign type 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't worked with the FFI before. The underlying value the canvas gives us will be a Number with an integral value. If I can just declare it as Int here and that works, that's great. If I need to explicitly call fromNumber
on it inside the js function I'm happy to do that too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs say height
is "an unsigned long representing the actual height" for example. I think we can use Int
here.
The reason for the current code is that Number
was the only option back when this was added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the underlying representation of Int still just a Number? I'm not sure whether I can just declare the type here and it works or if I need to actually coerce the Number to an Int.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it's just a number. They're syntactically forced to be actual ints in the compiler, and the operators are modified to preserve integerness.
Looks nice! I'm happy to make a major version release since the type changes make things much simpler IMO. |
Alright, updated those to |
@@ -23,6 +23,7 @@ | |||
"purescript-eff": "^0.1.0", | |||
"purescript-functions": "^0.1.0", | |||
"purescript-maybe": "^0.3.0", | |||
"purescript-exceptions": "^0.3.1" | |||
"purescript-exceptions": "^0.3.1", | |||
"purescript-arraybugger-types": "^0.2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arraybuffer-types
😄
This is what I get for testing my changes by copy/pasting into an existing bower_modules/ folder. Sorry
Ugh. So, learning opportunity: what is the right way to actually try the local changes in a library like this that isn't runnable itself? I was literally copy/pasting changes into another instance of purescript-canvas inside the bower-modules of a project I was building. But that obviously doesn't cover problems like this. |
We can add a |
Ok I can confirm that was failing before the spelling change and passes On Wed, Dec 16, 2015 at 9:26 PM, Phil Freeman [email protected]
|
Expose the information in the ImageData type.
Thanks! |
This is my first contribution to a purescript module in public use, so let me know if I've done something wrong. In particular, I've removed some signatures that could be backwards-compatibly implemented, but would perhaps be confusing in the future. I don't know how this community thinks about changing contracts in releases so I am happy to put them back.